import Joi from '@hapi/joi';
import { ConfigModule } from '@nestjs/config';

export const setupConfig = () => {
  return ConfigModule.forRoot({
    validationSchema: Joi.object({
      NODE_ENV: Joi.string().valid('development', 'production', 'test', 'provision').default('development'),
      PORT: Joi.number().default(3000),
      JWT_SECRET: Joi.string(),
      JWT_EXPIRES_IN: Joi.string(),
      DATABASE_TYPE: Joi.string().valid('mysql', 'postgres', 'sqlite', 'mariadb', 'mssql', 'db2', 'snowflake', 'oracle').default('mysql'),
      DATABASE_HOST: Joi.string().default('localhost'),
      DATABASE_PORT: Joi.number().default(3306),
      DATABASE_USERNAME: Joi.string(),
      DATABASE_PASSWORD: Joi.string(),
      DATABASE_DATABASE: Joi.string(),
      API_THROTTLE_TIME: Joi.number().default(60000),
      API_THROTTLE_LIMIT: Joi.number().default(10),
      APP_BASE_URL: Joi.string(),
      USER_ONLINE_NUMBER: Joi.number().default(1)
    }),
    validationOptions: {
      allowUnknown: true,
      abortEarly: true
    },
    isGlobal: true,
    envFilePath: ['.env.development.local', '.env.development', '.env']
  });
};
